#W3_2. 给定两个字符串，写一个函数，返回这两个字符串中最长的相同部分。例如"knowledge"和"known"相同的最长部分是"know"
str1 = 'knowledge'
str2 = 'know'
def max_same_substr(s1,s2):
    def all_substr(s1):
        length = len(s1)
        lst = [s1[i:j] for i in range(length) for j in range(i+1,length+1)]
        return lst
    def max_substr(l1,l2):
        set1 = set(l1)
        set2 = set(l2)
        ans_list = list(set1 & set2)    
        max_length = max([len(i) for i in ans_list])
        max_length_substr = [ i for i in ans_list if len(i) == max_length]
        return max_length_substr
    return max_substr(all_substr(s1),all_substr(s2))
for i in max_same_substr(str1,str2):
    print('最长字符串是{}'.format(i))
